package com.woniuxy.hrp.mapper;/**
 * @Description：
 * @Author：曹杰克
 * @CreateTime：2022/9/6 21:00
 */

import com.woniuxy.hrp.entity.DoctorAndPatientAndItem;
import com.woniuxy.hrp.entity.Hospital;
import com.woniuxy.hrp.entity.Patient;
import com.woniuxy.hrp.entity.Reservation;
import com.woniuxy.hrp.provider.PatientMapperSqlProvider;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 *@Description：
 *@CreateTime：2022/9/6 21:00
 *@Author：曹杰克
 */
@Mapper
public interface DoctorAndPatientAndItemMapper {
    /**
     * 根据就诊id获取所有的医生检查信息
     * @param MrecordId
     * @return
     */
    @Select("select * from hrp_doctor_patient_item where mrecord_id=#{MrecordId}")
    @Results({
            @Result(column = "mitem_id",property = "mitem",one= @One(select = "com.woniuxy.hrp.mapper.MitemMapper.getById")),
            @Result(column = "doctor_id",property = "doctor",one = @One(select = "com.woniuxy.hrp.mapper.DoctorMapper.selectByDoctorId"))
    })
    public List<DoctorAndPatientAndItem> selectByMrecordId(int MrecordId);

    /**
     * 查询所有的检查项目记录
     * @return
     */
    @Select("select * from hrp_doctor_patient_item")
    @Results({
            @Result(column = "mitem_id",property = "mitem",one= @One(select = "com.woniuxy.hrp.mapper.MitemMapper.getById", fetchType = FetchType.LAZY)),
            @Result(column = "mrecord_id",property = "mrecord",one= @One(select = "com.woniuxy.hrp.mapper.MrecordMapper.getByMrecordId", fetchType = FetchType.LAZY)),
            @Result(column = "doctor_id",property = "doctor",one = @One(select = "com.woniuxy.hrp.mapper.DoctorMapper.selectByDoctorId", fetchType = FetchType.LAZY))
    })
    List<DoctorAndPatientAndItem> getAll();

    /**
     * 根据就诊id获取检查信息
     * @return
     */
    @Select("select * from hrp_doctor_patient_item where id =#{id}")
    @Results({
            @Result(column = "mitem_id",property = "mitem",one= @One(select = "com.woniuxy.hrp.mapper.MitemMapper.getById")),
            @Result(column = "mrecord_id",property = "mrecord",one= @One(select = "com.woniuxy.hrp.mapper.MrecordMapper.seleByMrecordId")),
            @Result(column = "doctor_id",property = "doctor",one = @One(select = "com.woniuxy.hrp.mapper.DoctorMapper.selectByDoctorId"))
    })
    DoctorAndPatientAndItem getById(int id);

    /**
     *@Description 根据就诊记录id + 检查状态为已支付时 更新上传检查结果
     *@param:
     * @return: void
     * @author shanshanfan
     * @date: 2022/9/7 20:11
     **/
    @Update("update hrp_doctor_patient_item set result=#{result} where id=#{id} and status='Y'")
    void updateById(DoctorAndPatientAndItem doctorAndPatientAndItem);


    @Insert("insert into hrp_doctor_patient_item (doctor_id,mitem_id,status) values(#{doctor.id},#{mitem.id},#{status})")
    void add(DoctorAndPatientAndItem doctorAndPatientAndItem);
}
